<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加课程续费预警</title>
    <link rel="stylesheet" href="/scriptZIP/layui.min.css">
    <link rel="stylesheet" href="../css/item.css">
    <link rel="stylesheet" href="../css/layui.css">
    <style>
        .layui-row {
            margin-top: 50px;
        }
    </style>
</head>

<body>
    <div class="layui-row" id="vue-root">
        <div class="layui-col-md6 layui-col-md-offset3">
            <div class="layui-form-item">
                <label class="layui-form-label">剩余课时≤</label>
                <div class="layui-input-block">
                    <input name="termName" v-validate="'required'" data-vv-as="剩余课时" autocomplete="off"
                        placeholder="请输入剩余课时到期提醒" class="layui-input name" v-model="item.numHours">
                    <div class="checkout_state"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">剩余天数≤</label>
                <div class="layui-input-block">
                    <input name="termName" v-validate="'required'" data-vv-as="剩余天数" autocomplete="off"
                        placeholder="请输入剩余天数到期提醒" class="layui-input name" v-model="item.numDays">
                    <div class="checkout_state"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="offer" @click="submit">立即提交</div>
                    <div class="return" onclick="history.back()">取消</div>
                </div>
            </div>
        </div>
    </div>

    <script src="/scriptZIP/qs.min.js"></script>
    <script src="/scriptZIP/vue.min.js"></script>
    <script src="/scriptZIP/axios.min.js"></script>

    <script src="/js/common.js"></script>
    <script src="/js/item.js"></script>

    <script>
        var app = new Vue({
            el: '#vue-root',
            data: {
                item: {
                    numHours: 0,
                    numDays: 0,
                    id: null, // 用于存储获取到的ID
                    schoolId: top_params().id,
                    disabled: false
                },
                url: '/pc/curriculum/' + top_params().id
            },
            created() {
                this.fetchData();
            },
            methods: {
                fetchData() {
                    axios.get(this.url)
                        .then(response => {
                            let data = response.data;
                            this.item.numHours = data.numHours;
                            this.item.numDays = data.numDays;
                            this.item.id = data.id; // 获取并存储ID
                        })
                        .catch(error => {
                            console.error("获取数据时出错:", error);
                        });
                },
                submit() {
                    axios.put('/pc/curriculum', {
                        numHours: this.item.numHours,
                        numDays: this.item.numDays,
                        id: this.item.id // 在提交时传递ID
                    })
                    .then(response => {
                        alert("预警设置成功");
                        location.href='warning_reminder.html'

                    })
                    .catch(error => {
                        console.error("提交数据时出错:", error);
                    });
                }
            }
        });
    </script>
</body>

</html>
